import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { observer, inject } from "@tarojs/mobx-rn";
import { View, Swiper, SwiperItem, Image, Text } from "@tarojs/components-rn";
import { toJS } from "mobx";
import { getRuntime, partOf, getAvatar, typeOfJob, subtime } from "../../utils/common";
import Tabbar from "../../components/Tabbar";
import indexStyleSheet from "./index_styles";
import icon_05 from '../../assets/img/icon_05.png';
import icon_06 from '../../assets/img/icon_06.png';
import icon_08 from '../../assets/img/icon_08.png';
import icon_09 from '../../assets/img/icon_09.png';
import icon_10 from '../../assets/img/icon_10.png';
import icon_11 from '../../assets/img/icon_11.png';
import icon_12 from '../../assets/img/icon_12.png';
import icon_13 from '../../assets/img/icon_13.png';
import icon_14 from '../../assets/img/icon_14.png';
import icon_15 from '../../assets/img/icon_15.png';
import notice from '../../assets/img/icon_17.png';
import img_04 from '../../assets/img/img_04.jpg';
import img_05 from '../../assets/img/img_05.jpg';
import img_06 from '../../assets/img/img_06.jpg';
var _styleSheet = indexStyleSheet;
let Index = class Index extends Component {
  constructor() {
    super(...arguments);
    this.state = {
      upBanners: [],
      scrollingCaption: [],
      infoMations: [],
      issueShow: false,
      isTips: false,
      tipsText: '请先进行登录~'
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '建务通' });
    const { stores: { homeStore } } = this.props;
    let home = toJS(homeStore.home);
    if (Object.keys(home).length > 0) {
      this.setState({
        upBanners: toJS(home.upBanners),
        infoMations: toJS(home.infoMations),
        scrollingCaption: toJS(home.scrollingCaption)
      });
    } else {
      homeStore.getHomeInfo({
        callback: homeInfo => {
          this.setState({
            upBanners: toJS(homeInfo.upBanners),
            infoMations: toJS(homeInfo.infoMations),
            scrollingCaption: toJS(homeInfo.scrollingCaption)
          });
        }
      });
    }
  }
  link(url) {
    if (url) {
      window.location.href = url;
    }
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  handelUpgrade(url = '/pages/index/index') {
    if (!getRuntime().getToken()) {
      getRuntime().navigateTo('/pages/login/login');
      return;
    }
    getRuntime().navigateTo(url);
  }
  /**
   * swiper因为需要手指左右滑动，禁用了swiper的点击效果，需要去取消默认动作
   */
  componentDidUpdate() {
    var bannerItems = document.getElementsByClassName('swiper-item-notice'),
        _this = this;
    let { scrollingCaption } = this.state;
    for (let i = 0, length = bannerItems.length; i < length; i++) {
      bannerItems[i].onclick = function (e) {
        e.stopPropagation();
        //e.preventDefault(); // 取消事件默认动作
        _this.handelRouter('/pages/user/help_detail?id=' + scrollingCaption[i]['id']);
      };
    }
  }
  render() {
    let { upBanners, infoMations, scrollingCaption } = this.state;
    return <View style={_styleSheet["index-wrap"]}>
        <View style={_styleSheet["swiper-wrap"]}>
          <Swiper indicatorColor="#fff" indicatorActiveColor="#00a0e9" indicatorDots style={_styleSheet["swiper"]}>
            {upBanners && upBanners.map(item => {
            return <SwiperItem key={item.id} style={_styleSheet["swiper-item"]}>
                  <Image src={item.picture} onClick={this.link.bind(this, item.url)} style={_styleSheet["swiper-img"]} />
                </SwiperItem>;
          })}
          </Swiper>
        </View>
        {scrollingCaption.length > 0 && <View style={_styleSheet["notice-wrap"]}>
             <View style={_styleSheet["notice"]}>
                <Image src={notice} style={_styleSheet["notice-img"]} />
                <View style={_styleSheet["notice-content"]}>
                   <Swiper circular={false} indicatorDots={false} autoplay={true} style={_styleSheet["swiper"]}>
                     {scrollingCaption.map(item => {
                return <SwiperItem key={item.id} date-itemId={item.id} onClick={this.handelRouter.bind(this, '/pages/user/help_detail?id=' + item.id)} style={_styleSheet["swiper-item-notice"]}>
                            <View style={_styleSheet["title"]}>{item.title}</View>
                           </SwiperItem>;
              })}
              </Swiper>
                </View>
             </View>
          </View>}

        <View style={_styleSheet["index-nav"]}>
          <View onClick={this.handelRouter.bind(this, '/pages/all_services/none')} style={_styleSheet["nav"]}>
            <Image src={icon_05} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>政府政务中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/legal/index')} style={_styleSheet["nav"]}>
            <Image src={icon_06} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>律政中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/finance/index')} style={_styleSheet["nav"]}>
            <Image src={icon_08} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>工程金融中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/business/index')} style={_styleSheet["nav"]}>
            <Image src={icon_09} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>工商服务中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/library/index')} style={_styleSheet["nav"]}>
            <Image src={icon_10} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>建务库中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/company_credit/index')} style={_styleSheet["nav"]}>
            <Image src={icon_11} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>企业信用中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/newest/personnel_center')} style={_styleSheet["nav"]}>
            <Image src={icon_12} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>工程人才中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/business_school/index')} style={_styleSheet["nav"]}>
            <Image src={icon_13} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>建企商学院</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/tendering/index')} style={_styleSheet["nav"]}>
            <Image src={icon_14} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>投招标中心</Text>
          </View>
          <View onClick={this.handelRouter.bind(this, '/pages/all_services/index')} style={_styleSheet["nav"]}>
            <Image src={icon_15} style={_styleSheet["nav-icon"]} />
            <Text style={_styleSheet["nav-title"]}>全部服务</Text>
          </View>
        </View>

        <View style={_styleSheet["interval"]} />

        {infoMations.length > 0 && <View style={[_styleSheet["column-title"], _styleSheet["content-30"]]}>
             <Text style={_styleSheet["column-name"]}>最新消息</Text>
             <Text onClick={this.handelRouter.bind(this, '/pages/newest/index')} style={_styleSheet["column-more"]}>查看更多 > </Text>
          </View>}

        <View style={_styleSheet["list-01"]}>
          {infoMations.length > 0 && infoMations.map(item => {
          let tpl = null;
          switch (item.publicationType) {
            case 1:
              {
                // 需求
                tpl = <View onClick={this.handelRouter.bind(this, '/pages/newest/demand_detail?id=' + item.id)} style={_styleSheet["item"]}>
                      <Text style={_styleSheet["title"]}>{partOf(item.description, 40)}</Text>
                      <View style={_styleSheet["info"]}>
                        <View style={_styleSheet["author"]}>
                          <Image src={getAvatar(item.userLogoImg)} style={_styleSheet["author-pic"]} />
                          <Text style={_styleSheet["author-name"]}>{item.userNickName}</Text>
                        </View>
                        <View style={_styleSheet["time"]}>
                          {subtime(item.creationTime)}
                          <Text style={[_styleSheet["type"], _styleSheet["type-demand"]]}>需求</Text>
                        </View>
                      </View>
                    </View>;
                break;
              }
            case 2:
              {
                // 服务
                tpl = <View onClick={this.handelRouter.bind(this, '/pages/newest/service_detail?id=' + item.id)} style={_styleSheet["item"]}>
                      <Text style={_styleSheet["title"]}>{partOf(item.description, 40)}</Text>
                      <View style={_styleSheet["info"]}>
                        <View style={_styleSheet["author"]}>
                          <Image src={getAvatar(item.userLogoImg)} style={_styleSheet["author-pic"]} />
                          <Text style={_styleSheet["author-name"]}>{item.userNickName}</Text>
                        </View>
                        <View style={_styleSheet["time"]}>
                          {subtime(item.creationTime)}
                          <Text style={[_styleSheet["type"], _styleSheet["type-services"]]}>服务</Text>
                        </View>
                      </View>
                    </View>;
                break;
              }
            case 3:
              {
                // 职位
                tpl = <View onClick={this.handelRouter.bind(this, '/pages/newest/position_detail?id=' + item.id)} style={[_styleSheet["item"], _styleSheet["item-other"]]}>
                      <View style={_styleSheet["top"]}>
                        <View style={_styleSheet["title"]}>
                          <Text style={_styleSheet["label"]}>{item.jobNature}</Text>
                          {item.positionName}
                        </View>
                        <View style={_styleSheet["price"]}>{item.monthlyPay}</View>
                      </View>

                      <View style={_styleSheet["bottom"]}>
                        <View style={_styleSheet["label"]}>
                          <Text style={_styleSheet["label-text"]}>{item.education}</Text>
                          <Text style={_styleSheet["label-text"]}>{item.technicalTitle}</Text>
                          <Text style={_styleSheet["label-text"]}>{item.recruitment}人</Text>
                          
                        </View>
                        <View style={_styleSheet["time"]}>
                          {subtime(item.creationTime)}
                          <Text style={[_styleSheet["type"], _styleSheet["type-position"]]}>职位</Text>
                        </View>
                      </View>
                    </View>;
                break;
              }
            default:
              {
                // 简历
                tpl = <View onClick={this.handelRouter.bind(this, '/pages/newest/personnel_detail?id=' + item.id)} style={[_styleSheet["item"], _styleSheet["item-other"]]}>
                      <View style={_styleSheet["top"]}>
                        <View style={_styleSheet["title"]}>
                          <Text style={_styleSheet["label"]}>{typeOfJob(item.typeOfJob)}</Text>
                          {item.positionName}
                        </View>
                        <View style={_styleSheet["price"]}>{item.monthlyPay}</View>
                      </View>

                      <View style={_styleSheet["bottom"]}>
                        <View style={_styleSheet["label"]}>
                          <Text style={_styleSheet["label-text"]}>{item.education}</Text>
                          <Text style={[_styleSheet["label-text"], _styleSheet["brnone"]]}>{item.technicalTitle}</Text>
                        </View>
                        <View style={_styleSheet["time"]}>
                          {subtime(item.creationTime)}
                          <Text style={[_styleSheet["type"], _styleSheet["type-resume"]]}>人才</Text>
                        </View>
                      </View>
                    </View>;
              }
          }
          return tpl;
        })}
        </View>
        <View style={_styleSheet["interval"]} />

        <View style={[_styleSheet["theme"], _styleSheet["content-30"]]}>
          <Image src={img_04} onClick={this.handelUpgrade.bind(this, '/pages/user/upgrade?id=3')} style={_styleSheet["l-img"]} />
          <View style={_styleSheet["r"]}>
            <Image src={img_05} onClick={this.handelUpgrade.bind(this, '/pages/user/upgrade?id=3')} style={_styleSheet["r-img"]} />
            <Image src={img_06} onClick={this.handelUpgrade.bind(this, '/pages/user/qrcode')} style={_styleSheet["r-img"]} />
          </View>
        </View>

        <View style={_styleSheet["page-footer"]}>
          技术支持：云南西部硅谷
        </View>

        <Tabbar currentTab="home" />
      </View>;
  }
};
Index = tslib_1.__decorate([inject("stores"), observer], Index);
export default Index;